import CompEle from './CompEle'
import Ele from './Ele'
import ViewRouter from '../router/ViewRouter'
export default class RouterEle extends Ele{
    constructor (subject, ele) {
        super(subject, ele)
        this.name = this.ele.getAttribute('name') || 'default'
        if (this.subject.route[this.name]) {
            throw '重复定义路由视图名：' +  this.name
        }
        this.subject.routes.forEach((route) => {
            if (route.name && route.name == this.name) {
                this.subject.route[this.name] = new ViewRouter(this.ele, this.subject, route)
            }else if (route.name  == undefined) {
                if (this.name == 'default') {
                    route.name = 'default'
                    this.subject.route[this.name] = new ViewRouter(this.ele, this.subject, route)
                }
            }
        })
    }
}